efc58cdea3917b0b7e88240c03d51c2a2e64a62e,agent-simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java,MockStorageManagerImpl,BackupSnapshot,#BackupSnapshotCommand#SimulatorInfo#,419
Before Change
return new BackupSnapshotAnswer(cmd, false, "Can't find base volume: " + cmd.getVolumePath(), null, true);
}
String snapshotPath = cmd.getSnapshotUuid();
MockVolumeVO snapshot = _mockVolumeDao.findByStoragePathAndType(snapshotPath);
if (snapshot == null) {
return new BackupSnapshotAnswer(cmd, false, "can't find snapshot" + snapshotPath, null, true);
}
After Change
MockVolumeVO volume = null;
MockVolumeVO snapshot = null;
MockSecStorageVO secStorage = null;
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
try {
txn.start();
volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
if (volume == null) {
return new BackupSnapshotAnswer(cmd, false, "Can't find base volume: " + cmd.getVolumePath(), null,
true);
}
String snapshotPath = cmd.getSnapshotUuid();
snapshot = _mockVolumeDao.findByStoragePathAndType(snapshotPath);
if (snapshot == null) {
return new BackupSnapshotAnswer(cmd, false, "can't find snapshot" + snapshotPath, null, true);
}
String secStorageUrl = cmd.getSecondaryStorageUrl();
secStorage = _mockSecStorageDao.findByUrl(secStorageUrl);
if (secStorage == null) {
return new BackupSnapshotAnswer(cmd, false, "can't find sec storage" + snapshotPath, null, true);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when backing up snapshot");
} finally {
txn.close();
txn = Transaction.open(Transaction.CLOUD_DB);
txn.close();
}
MockVolumeVO newsnapshot = new MockVolumeVO();
String name = UUID.randomUUID().toString();
newsnapshot.setName(name);
newsnapshot.setPath(secStorage.getMountPoint() + name);
newsnapshot.setPoolId(secStorage.getId());
newsnapshot.setSize(snapshot.getSize());
newsnapshot.setStatus(Status.DOWNLOADED);
newsnapshot.setType(MockVolumeType.SNAPSHOT);
txn = Transaction.open(Transaction.SIMULATOR_DB);
try {
txn.start();
snapshot = _mockVolumeDao.persist(snapshot);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when backing up snapshot " + newsnapshot, ex);
} finally {
txn.close();
txn = Transaction.open(Transaction.CLOUD_DB);